from typing import List, TYPE_CHECKING, Union, Callable, ClassVar,Optional, Any
from pydantic import EmailStr,computed_field
from datetime import datetime,date
from sqlmodel import  SQLModel,text,Column,TEXT,Field,Relationship
from .base import SQLModelBase
from .resBase import BaseResponse, PaginationRequest, PaginatedResponse, PaginationInfo
import sqlalchemy as sa
from enum import Enum
# from sqlalchemy.orm import Relationship

if TYPE_CHECKING:
    from .userAuth import UserAuth
    from .article import Article
 
class SearchCondition(SQLModel):
    s_time: str  # 比赛开始时间 yyyy-mm-dd
    e_time: str  # 比赛结束时间
    event_name: str | None = None  # 赛事名称，可选参数用于筛选

    
class Matches(SQLModel):
    event_name:str | None = None
    fid :int | None = None
    homesxname :str | None = None
    awaysxname :str | None = None
    matchtime :datetime | None = None
    homescore :int | None = None
    awayscore :int | None = None
    

class MatchesResultResponse(BaseResponse):
    data: list[Matches] | None      
          
# 信号值
from sqlmodel import SQLModel, Field
from datetime import datetime
from typing import Optional

class Signal(SQLModel):
    fid: Optional[int] = Field(default=None, primary_key=True)
    odds_time: str = Field(primary_key=True)
    home_odds: float
    draw_odds: float
    away_odds: float
    prob_home_odds: float
    prob_draw_odds: float
    prob_away_odds: float
    return_rate: float
    home_kelly: float
    draw_kelly: float
    away_kelly: float
    market_home: float
    market_draw: float
    market_away: float
    market_total: float
    guiyi_home: float
    guiyi_draw: float
    guiyi_away: float
    rezhi_home: float
    rezhi_draw: float
    rezhi_away: float
    signal_home: float
    signal_draw: float
    signal_away: float
    
    
class Signal_18(Signal,SQLModel, table=True):
    # 定义表参数
    __tablename__: str = "t_football_odds_500_18_signal_final" 

class Signal_293(Signal,SQLModel, table=True):
    # 定义表参数
    __tablename__: str = "t_football_odds_500_293_signal_final" 
    
    

class SignalResultResponse(BaseResponse):
    data: list[Signal_18 | Signal_293] | None  

class SignalCondition(SQLModel):
    fid: int  # 比赛id
    company_id: int  # 博彩公司id 293 威廉希尔,18 必发

class EventList(SQLModel):
    event_name: str | None = None

class EventListResultResponse(BaseResponse):
    data: list[EventList] | None

class SimilarMatches(SQLModel):
    event_name: str | None = None
    order_num: str | None = None
    fid: int | None = None
    matchtime: datetime | None = None
    homesxname: str | None = None
    awaysxname: str | None = None
    homescore: int | None = None
    awayscore: int | None = None
    home_initial: float | None = None
    draw_initial: float | None = None
    away_initial: float | None = None
    home_final: float | None = None
    draw_final: float | None = None
    away_final: float | None = None
    signal_home_initial: float | None = None
    signal_draw_initial: float | None = None
    signal_away_initial: float | None = None
    signal_home_final: float | None = None
    signal_draw_final: float | None = None
    signal_away_final: float | None = None

class SimilarMatchesCondition(PaginationRequest):
    event_name: str | None = None  # 赛事名称，可选参数
    home_initial_min: float  # 主队初始赔率最小值
    home_initial_max: float  # 主队初始赔率最大值
    draw_initial_min: float  # 平局初始赔率最小值
    draw_initial_max: float  # 平局初始赔率最大值
    away_initial_min: float  # 客队初始赔率最小值
    away_initial_max: float  # 客队初始赔率最大值
    signal_home_initial_min: float  # 主队初始信号最小值
    signal_home_initial_max: float  # 主队初始信号最大值
    signal_draw_initial_min: float  # 平局初始信号最小值
    signal_draw_initial_max: float  # 平局初始信号最大值
    signal_away_initial_min: float  # 客队初始信号最小值
    signal_away_initial_max: float  # 客队初始信号最大值

class MatchStatistics(SQLModel):
    total_matches: int
    home_wins: int
    draws: int
    away_wins: int
    home_win_rate: float
    draw_rate: float
    away_win_rate: float

class SimilarMatchesResultResponse(PaginatedResponse):
    data: list[SimilarMatches] | None
    statistics: MatchStatistics | None
